<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html">
    <body>
        <ui:composition template="./templates/default.xhtml">
            <ui:define name="content">
                <link rel="stylesheet" type="text/css" href="resources/css/default.css"/>
                <h:form binding="#{messageManagerBean.loadMessagesPage}">
                    <p:panel header="My Messages" id="messagesPanel">
                        <h:outputText id="output" value="#{messageManagerBean.type} has #{messageManagerBean.count} items." />
                        <h:selectOneMenu id="messageType" value="#{messageManagerBean.type}">  
                            <f:selectItem itemLabel="Inbox" itemValue="Inbox" /> 
                            <f:selectItem itemLabel="Sent Items" itemValue="Sent Items" />  
                            <p:ajax update="messages,output"   
                                    listener="#{messageManagerBean.loadChange}" />  
                            <p:ajaxStatus style="width:16px;height:16px;">  
                                <f:facet name="start">  
                                    <h:graphicImage value="resources/images/ajaxloading.gif" />  
                                </f:facet>  
                                <f:facet name="complete">  
                                    <h:outputText value="" />  
                                </f:facet>  
                            </p:ajaxStatus>  
                        </h:selectOneMenu><hr />
                        <p:dataTable id="messages" var="message" value="#{messageManagerBean.messages}" paginator="true" 
                                     selectionMode="single" rowSelectListener="#{messageManagerBean.onRowSelect}"
                                     emptyMessage="No messages found with given criteria."
                                     selection="#{messageManagerBean.selectedMessage}" update="status"
                                     rowStyleClass="#{!message.messageStatus and messageManagerBean.isInbox ? 'message-table-row' : null }"
                                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                                     rowsPerPageTemplate="5,10,15" rows="10" >
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Select" />
                                </f:facet>
                                <h:selectBooleanCheckbox value="#{messageManagerBean.selectedIds[message.messageId]}" />
                            </p:column>
                            <p:column filterBy="#{message.subject}" headerText="Subject" filterMatchMode="contains">  
                                <h:outputText value="#{message.subject}" />  
                            </p:column> 
                            <p:column filterBy="#{message.senderId}" headerText="Sender" filterMatchMode="contains">  
                                <h:outputText value="#{message.senderId}" />  
                            </p:column> 
                            <p:column filterBy="#{message.receiverId}" headerText="Receiver" filterMatchMode="contains">  
                                <h:outputText value="#{message.receiverId}" />  
                            </p:column> 
                            <p:column headerText="Message Date"> 
                                <h:outputText value="#{message.messageDate}">  
                                    <f:convertDateTime pattern="dd-MM-yyyy hh:mm a" timeZone="#{defaultManagerBean.tz}"/>
                                </h:outputText>
                            </p:column>
                        </p:dataTable>
                        <p:commandButton value="Delete Message" actionListener="#{messageManagerBean.deleteMessage}" ajax="true"
                                                                          disabled="#{messageManagerBean.deleteButtonStatus}"/>
                        <p:commandButton value="Send a Message" update="status" id="sendMessage" actionListener="#{messageManagerBean.redirect}"/>
                        <hr />
                    </p:panel>
                </h:form>
            </ui:define>
        </ui:composition>
    </body>
</html>